import java.awt.*;
import java.awt.event.*;
import java.util.Scanner;

/**
 * Created by IntelliJ IDEA.
 * User: zm
 * Date: 2023/4/10
 */

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class Demo14 extends JFrame {


    public static void main(String[] args) {
        Frame frame = new Frame();

        //定义组件--->按钮
        Button button1 = new Button("button1");

        //设置大小
        frame.setSize(500, 500);

        //设置布局  流式布局
        frame.setLayout(new FlowLayout());//居中  默认

        //添加组件-->按钮
        frame.add(button1);

        //设置窗口可见
        frame.setVisible(true);

        //关闭
        frame.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
    }


    class WoDeMianBan extends JPanel implements MouseListener, KeyListener, MouseMotionListener {
        public void paint(Graphics g) {
            super.paint(g);
        }

        public void mouseClicked(MouseEvent e) {
            System.out.println("鼠标单击了按钮");
        }

        @Override// 表示下面是重写方法，让编译器帮你改错，如果不写也无大碍，但是方法写错了编译器会以为是你自定义的方法
        public void mousePressed(MouseEvent e) {
            System.out.println("鼠标被按下");
            Object obj = e.getSource();
        }

        public void mouseReleased(MouseEvent e) {
            // System.out.println("鼠标被松开");
        }

        public void mouseEntered(MouseEvent e) {
            // System.out.println("鼠标移动到界面中");
        }

        public void mouseExited(MouseEvent e) {
            // System.out.println("鼠标离开界面");
        }


        @Override
        public void keyTyped(KeyEvent e) {

        }

        @Override
        public void keyPressed(KeyEvent e) {

        }

        @Override
        public void keyReleased(KeyEvent e) {

        }

        @Override
        public void mouseDragged(MouseEvent e) {

        }

        @Override
        public void mouseMoved(MouseEvent e) {

        }
    }
}